<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
			<!-- Metas -->
		    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
		    <meta name="viewport" content="width=device-width, initial-scale=1.0">
		    <meta name="author" content="Vision" />
		    <!-- Links -->
		    <link rel="icon" type="image/png" href="images/favicon.png" />
		    <link href="https://fonts.googleapis.com/css?family=Work+Sans:400,600&display=swap" rel="stylesheet">
		    <link rel="stylesheet" href="icofont.min.css">
		    <link href="css/bootstrap.min.css" rel="stylesheet" />
		    <link href="css/slick.css" rel="stylesheet" />
		    
		    <link href="css/main.css" rel="stylesheet" />
			<title></title>
			<link rel="stylesheet" href="layui/css/layui.css"/>
		</head>
		<body>
		<header id="home">
		<div class="container">
		  <nav class="navbar navbar-expand-lg navbar-light ">
		    <!-- Change Logo Img Here -->
		    <a class="navbar-brand" href="#"><img src="images/logo.svg" alt=""></a>
		    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
		      <div class="interactive-menu-button">
		        <a href="#">
		          <span>Menu</span>
		        </a>
		      </div>
		    </button>
		    <div class="collapse navbar-collapse" id="navbarSupportedContent">
		      <ul class="navbar-nav mr-auto">
		        <li class="nav-item">
		          <!-- Nav Link -->
		          <a class="nav-link" data-scroll href="index.html">主页.<span class="sr-only">(current)</span></a>
		        </li>
		        <li class="nav-item">
		          <!-- Nav Link -->
		          <a class="nav-link" data-scroll href="food.html">食品.</a>
		        </li>
		        <li class="nav-item">
		          <!-- Nav Link -->
		          <a class="nav-link" data-scroll href="batch.html">批次.</a>
		        </li>
		        <li class="nav-item">
		          <!-- Nav Link -->
		          <a class="nav-link active" data-scroll href="user.html">人员管理.</a>
		        </li>
		        <li class="nav-item">
		          <!-- Nav Link -->
		          <a class="nav-link" data-scroll href="about.html">关于我们.</a>
		        </li>
				<li class="nav-item">
				  <!-- Nav Link -->
				  <a class="nav-link" data-scroll href="log.html">日志.</a>
				</li>
		        <!-- <li class="nav-item dropdown">
		         
		          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">EN</a>
		          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
		            <a class="dropdown-item" href="#">DE </a>
		            <a class="dropdown-item" href="#">ES </a>
		          </div>
		        </li> -->
		      </ul>
		      <a data-scroll href="my.html" class="contact-btn form-inline my-2 my-lg-0">
		        <!-- Contacgt Us Button -->
		        <button>个人信息</button>
		      </a>
		    </div>
		  </nav>
		</div>
		</header>
		<div align="center">
		  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		    <legend>修改密码</legend>
		  </fieldset>
		
		  <div class="layui-form">
		    <div class="layui-form-item">
		      <div class="layui-inline" >
		      <label class="layui-form-label">当前密码</label>
		      <div class="layui-input-inline">
		        <input type="password" id="oldPassword" name="oldPassword" lay-verify="required" lay-verType="tips" class="layui-input">
		      </div>
		      </div>
		    </div>
		    <div class="layui-form-item">
		       <div class="layui-inline" >
		      <label class="layui-form-label">新密码</label>
		      <div class="layui-input-inline">
		        <input type="password" name="password" lay-verify="required|pass" lay-verType="tips" autocomplete="off" id="LAY_password" class="layui-input">
		      </div>
		      <!-- <div class="layui-form-mid layui-word-aux">6到16个字符</div> -->
		    </div>
		     </div>
		    <div class="layui-form-item">
		      <div class="layui-inline" >
		      <label class="layui-form-label">确认新密码</label>
		      <div class="layui-input-inline">
		        <input type="password" name="repassword" lay-verify="required|repass" lay-verType="tips" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    </div>
		    <div class="layui-form-item">
		      <div class="layui-input-block">
		        <button class="layui-btn" id="alterPassword" lay-submit lay-filter="alterPassword">确认修改</button>
		      </div>
		    </div>
		  </div>
		</div>
	</body>
	<script src="layui/layui.js"></script>
	<script>
		layui.use(['table'], function(){
		      var $ = layui.$
		      ,layer = layui.layer
			    ,form = layui.form
			    ,admin = layui.admin,
					table = layui.table;
					
			    form.on('submit(alterPassword)', function (data) {
		        var formData = data.field;
		
		        if(formData.password != formData.repassword){
		          layer.msg("两次密码输入不一致！");
		          return;
		        }
		        $.ajax({
		              url: 'http://localhost:8080/foodman/admin/updatePassword',
					  async: false,
					  xhrFields: {withCredentials: true},
					  crossDomain: true,
					  processData: false, 
					  contentType: false, 
		              type: 'POST',
		              data: {oldPassword:formData.oldPassword,password:formData.password},
		              success: function (info) {
		                  if (info.code === 200) {
		                    layer.msg(info.msg);
		                      setTimeout(function () {
		                          location.href = 'login.html'
		                        }, 800);
		                  }else{
		                    layer.msg(info.msg);
		                  }
		              }
		        });
			});
		});
	</script>
</html>
